<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - gcov.info - curves/MinUnknownUniverseCover.cpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">curves</a> - MinUnknownUniverseCover.cpp<span style="font-size: 80%;"> (source / <a href="MinUnknownUniverseCover.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">gcov.info</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">80</td>
            <td class="headerCovTableEntry">80</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2014-06-30 01:17:31</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">9</td>
            <td class="headerCovTableEntry">9</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /* </a>
<span class="lineNum">       2 </span>            :  * File:   MinUnknownUniverseCover.cpp
<span class="lineNum">       3 </span>            :  * Author: nichole
<span class="lineNum">       4 </span>            :  * 
<span class="lineNum">       5 </span>            :  * Created on April 27, 2014
<span class="lineNum">       6 </span>            :  */
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : #include &quot;MinUnknownUniverseCover.h&quot;
<span class="lineNum">       9 </span>            : 
<a name="10"><span class="lineNum">      10 </span>            : namespace gev {</a>
<span class="lineNum">      11 </span>            :     
<span class="lineNum">      12 </span><span class="lineCov">          2 :     MinUnknownUniverseCover::MinUnknownUniverseCover() {</span>
<a name="13"><span class="lineNum">      13 </span><span class="lineCov">          4 :     }</span></a>
<span class="lineNum">      14 </span>            :     
<span class="lineNum">      15 </span><span class="lineCov">          6 :     MinUnknownUniverseCover::~MinUnknownUniverseCover() {</span>
<a name="16"><span class="lineNum">      16 </span><span class="lineCov">          6 :     }</span></a>
<span class="lineNum">      17 </span>            :         
<span class="lineNum">      18 </span>            :     void MinUnknownUniverseCover::calculateCover(
<span class="lineNum">      19 </span><span class="lineCov">          1 :         vector&lt; unordered_set&lt;uint32_t&gt; &gt;&amp; inputVariables,</span>
<span class="lineNum">      20 </span><span class="lineCov">          1 :         vector&lt;uint32_t&gt;&amp; outputCoverVariables) {</span>
<span class="lineNum">      21 </span>            :         
<span class="lineNum">      22 </span><span class="lineCov">          2 :         unordered_map&lt;uint32_t, uint32_t&gt; frequencyMap;</span>
<span class="lineNum">      23 </span>            :         
<span class="lineNum">      24 </span><span class="lineCov">          1 :         _populateVariableFrequencyMap(inputVariables, frequencyMap);</span>
<span class="lineNum">      25 </span>            :         
<span class="lineNum">      26 </span><span class="lineCov">          2 :         printf(&quot;\nread %lu unique parameter sets\n&quot;, frequencyMap.size());</span>
<span class="lineNum">      27 </span>            :         
<span class="lineNum">      28 </span><span class="lineCov">          1 :         printf(&quot;beginning set cover for parameters that generate all feasible curves\n&quot;);</span>
<span class="lineNum">      29 </span>            :         
<span class="lineNum">      30 </span><span class="lineCov">          1 :         _initializeVariableCover(frequencyMap, outputCoverVariables);</span>
<span class="lineNum">      31 </span>            :         
<span class="lineNum">      32 </span><span class="lineCov">          1 :         _findMinRepresentativeCover(inputVariables, outputCoverVariables);</span>
<span class="lineNum">      33 </span>            :         
<span class="lineNum">      34 </span>            :         //printf(&quot;\n calculateCover end\n&quot;);
<a name="35"><span class="lineNum">      35 </span><span class="lineCov">          1 :     }</span></a>
<span class="lineNum">      36 </span>            :     
<span class="lineNum">      37 </span>            :     void MinUnknownUniverseCover::_populateVariableFrequencyMap(
<span class="lineNum">      38 </span><span class="lineCov">          2 :         vector&lt; unordered_set&lt;uint32_t&gt; &gt;&amp; inputVariables,</span>
<span class="lineNum">      39 </span><span class="lineCov">          2 :         unordered_map&lt;uint32_t, uint32_t&gt;&amp; outVariableFrequencyMap) {</span>
<span class="lineNum">      40 </span>            :                 
<span class="lineNum">      41 </span><span class="lineCov">       2884 :         for (unsigned long i = 0; i &lt; inputVariables.size(); i++) {</span>
<span class="lineNum">      42 </span>            :             
<span class="lineNum">      43 </span><span class="lineCov">       1440 :             unordered_set&lt;uint32_t&gt; row = inputVariables[i];</span>
<span class="lineNum">      44 </span>            :             
<span class="lineNum">      45 </span><span class="lineCov">       4320 :             for (unordered_set&lt;uint32_t&gt;::const_iterator iter = row.begin();</span>
<span class="lineNum">      46 </span><span class="lineCov">    1201770 :                 iter != row.end(); ++iter) {</span>
<span class="lineNum">      47 </span>            :                 
<span class="lineNum">      48 </span><span class="lineCov">     478980 :                 int v = *iter;</span>
<span class="lineNum">      49 </span>            :                 
<span class="lineNum">      50 </span><span class="lineCov">     957960 :                 if (outVariableFrequencyMap.find(v) == outVariableFrequencyMap.end()) {</span>
<span class="lineNum">      51 </span><span class="lineCov">     718422 :                     outVariableFrequencyMap.insert(make_pair(v, 1));</span>
<span class="lineNum">      52 </span><span class="lineCov">     239474 :                 } else {</span>
<span class="lineNum">      53 </span><span class="lineCov">         32 :                     outVariableFrequencyMap[v]++;</span>
<span class="lineNum">      54 </span>            :                 }
<span class="lineNum">      55 </span><span class="lineCov">     239490 :             }</span>
<span class="lineNum">      56 </span><span class="lineCov">       1440 :         }</span>
<a name="57"><span class="lineNum">      57 </span><span class="lineCov">          2 :     }</span></a>
<span class="lineNum">      58 </span>            :     
<span class="lineNum">      59 </span>            :     void MinUnknownUniverseCover::_initializeVariableCover(
<span class="lineNum">      60 </span><span class="lineCov">          2 :         unordered_map&lt;uint32_t, uint32_t&gt;&amp; inputVariableFrequencyMap, </span>
<span class="lineNum">      61 </span><span class="lineCov">          2 :         vector&lt;uint32_t&gt;&amp; outputCoverVariables) {</span>
<span class="lineNum">      62 </span>            :         
<span class="lineNum">      63 </span>            :         //printf(&quot;\n initialize\n&quot;);
<span class="lineNum">      64 </span>            :         
<span class="lineNum">      65 </span><span class="lineCov">          2 :         outputCoverVariables.clear();</span>
<span class="lineNum">      66 </span><span class="lineCov">          4 :         vector&lt;uint32_t&gt; counts;</span>
<span class="lineNum">      67 </span>            :         
<span class="lineNum">      68 </span><span class="lineCov">          6 :         for (unordered_map&lt;uint32_t, uint32_t&gt;::const_iterator iter = </span>
<span class="lineNum">      69 </span><span class="lineCov">          4 :             inputVariableFrequencyMap.begin();  </span>
<span class="lineNum">      70 </span><span class="lineCov">    1197376 :             iter != inputVariableFrequencyMap.end(); ++iter) {</span>
<span class="lineNum">      71 </span>            :             
<span class="lineNum">      72 </span><span class="lineCov">     478948 :             int var = iter-&gt;first;</span>
<span class="lineNum">      73 </span><span class="lineCov">     478948 :             int count = iter-&gt;second;</span>
<span class="lineNum">      74 </span>            :             
<span class="lineNum">      75 </span><span class="lineCov">     239474 :             outputCoverVariables.push_back(var);</span>
<span class="lineNum">      76 </span><span class="lineCov">     239474 :             counts.push_back(count);</span>
<span class="lineNum">      77 </span><span class="lineCov">     239474 :         }</span>
<span class="lineNum">      78 </span>            :         
<span class="lineNum">      79 </span>            :         //printf(&quot;\n sort by frequency %lu variables\n&quot;, counts.size());
<span class="lineNum">      80 </span>            :         
<span class="lineNum">      81 </span>            :         // sort by frequency
<span class="lineNum">      82 </span><span class="lineCov">          6 :         Sorter *sorter = new Sorter();</span>
<span class="lineNum">      83 </span><span class="lineCov">          2 :         sorter-&gt;sort(counts, outputCoverVariables);</span>
<span class="lineNum">      84 </span><span class="lineCov">          6 :         delete sorter;</span>
<span class="lineNum">      85 </span>            :         
<span class="lineNum">      86 </span>            :         //printf(&quot;\n initialize end\n&quot;);
<a name="87"><span class="lineNum">      87 </span><span class="lineCov">          2 :     }</span></a>
<span class="lineNum">      88 </span>            :     
<span class="lineNum">      89 </span>            :     void MinUnknownUniverseCover::_findMinRepresentativeCover(
<span class="lineNum">      90 </span><span class="lineCov">          2 :         vector&lt; unordered_set&lt;uint32_t&gt; &gt;&amp; inputVariables, </span>
<span class="lineNum">      91 </span><span class="lineCov">          2 :         vector&lt;uint32_t&gt;&amp; outputCoverVariables) {</span>
<span class="lineNum">      92 </span>            :         
<span class="lineNum">      93 </span>            :         //printf(&quot;\n_findMinRepresentativeCover\n&quot;);
<span class="lineNum">      94 </span>            :         
<span class="lineNum">      95 </span><span class="lineCov">          2 :         unsigned long len = outputCoverVariables.size();</span>
<span class="lineNum">      96 </span>            :         
<span class="lineNum">      97 </span><span class="lineCov">          4 :         unordered_map&lt;uint32_t, uint32_t&gt; lookupIndexesMap;</span>
<span class="lineNum">      98 </span><span class="lineCov">     478952 :         for (unsigned long i = 0; i &lt; len; i++) {</span>
<span class="lineNum">      99 </span><span class="lineCov">     478948 :             int var = outputCoverVariables[i];</span>
<span class="lineNum">     100 </span><span class="lineCov">     718422 :             lookupIndexesMap.insert(make_pair(var, i));</span>
<span class="lineNum">     101 </span><span class="lineCov">     239474 :         }</span>
<span class="lineNum">     102 </span>            :         
<span class="lineNum">     103 </span>            :         
<span class="lineNum">     104 </span><span class="lineCov">          4 :         unordered_set&lt;uint32_t&gt; chose; </span>
<span class="lineNum">     105 </span>            :         
<span class="lineNum">     106 </span><span class="lineCov">          4 :         bool *doRemove = (bool*)calloc(len, sizeof(bool));</span>
<span class="lineNum">     107 </span>            :         
<span class="lineNum">     108 </span><span class="lineCov">     478952 :         for (unsigned long i = 0; i &lt; len; i++) {</span>
<span class="lineNum">     109 </span>            :             
<span class="lineNum">     110 </span><span class="lineCov">     239474 :             if (doRemove[i]) {</span>
<span class="lineNum">     111 </span><span class="lineCov">     238049 :                 continue;</span>
<span class="lineNum">     112 </span>            :             }
<span class="lineNum">     113 </span>            :             
<span class="lineNum">     114 </span><span class="lineCov">       2850 :             int var = outputCoverVariables[i];</span>
<span class="lineNum">     115 </span>            :             
<span class="lineNum">     116 </span><span class="lineCov">       1425 :             chose.insert(var);</span>
<span class="lineNum">     117 </span>            :                         
<span class="lineNum">     118 </span>            :             // search each row of inputVariables, and if var is in it, mark 
<span class="lineNum">     119 </span>            :             //   the remaining as doRemove
<span class="lineNum">     120 </span><span class="lineCov">    6126030 :             for (unsigned long ii = 0; ii &lt; inputVariables.size(); ii++) {</span>
<span class="lineNum">     121 </span>            :                 
<span class="lineNum">     122 </span><span class="lineCov">    4081170 :                 unordered_set&lt;uint32_t&gt; row = inputVariables[ii];</span>
<span class="lineNum">     123 </span>            :                 
<span class="lineNum">     124 </span><span class="lineCov">    8162340 :                 if (row.find(var) == row.end()) {</span>
<span class="lineNum">     125 </span><span class="lineCov">    2039145 :                     continue;</span>
<span class="lineNum">     126 </span>            :                 }
<span class="lineNum">     127 </span>            :                 
<span class="lineNum">     128 </span><span class="lineCov">       4320 :                 for (unordered_set&lt;uint32_t&gt;::const_iterator iter = row.begin();</span>
<span class="lineNum">     129 </span><span class="lineCov">    1201770 :                 iter != row.end(); ++iter) {</span>
<span class="lineNum">     130 </span>            :                 
<span class="lineNum">     131 </span><span class="lineCov">     478980 :                     int v = *iter;</span>
<span class="lineNum">     132 </span>            :                                             
<span class="lineNum">     133 </span><span class="lineCov">    1191690 :                     if ((v != var) &amp;&amp; (chose.find(v) == chose.end())) { </span>
<span class="lineNum">     134 </span><span class="lineCov">     714150 :                         int index = lookupIndexesMap.find(v)-&gt;second;</span>
<span class="lineNum">     135 </span><span class="lineCov">     238050 :                         doRemove[index] = true;</span>
<span class="lineNum">     136 </span><span class="lineCov">     238050 :                     }</span>
<span class="lineNum">     137 </span><span class="lineCov">     239490 :                 }</span>
<span class="lineNum">     138 </span><span class="lineCov">    2043465 :             }</span>
<span class="lineNum">     139 </span><span class="lineCov">       1425 :         }</span>
<span class="lineNum">     140 </span>            :         
<span class="lineNum">     141 </span><span class="lineCov">          8 :         outputCoverVariables.erase( outputCoverVariables.begin(),</span>
<span class="lineNum">     142 </span><span class="lineCov">          4 :             outputCoverVariables.end());</span>
<span class="lineNum">     143 </span>            :         
<span class="lineNum">     144 </span><span class="lineCov">          6 :         for (unordered_set&lt;uint32_t&gt;::const_iterator iter = chose.begin();</span>
<span class="lineNum">     145 </span><span class="lineCov">       7131 :             iter != chose.end(); ++iter) {</span>
<span class="lineNum">     146 </span>            :                 
<span class="lineNum">     147 </span><span class="lineCov">       2850 :             int v = *iter;</span>
<span class="lineNum">     148 </span>            :             
<span class="lineNum">     149 </span><span class="lineCov">       1425 :             outputCoverVariables.push_back(v);</span>
<span class="lineNum">     150 </span><span class="lineCov">       1425 :         }</span>
<span class="lineNum">     151 </span>            :         
<span class="lineNum">     152 </span>            :         // TODO: when there are more than one variable as the possible choice to 
<span class="lineNum">     153 </span>            :         //   represent a row, choose the one which is closer to answers already
<span class="lineNum">     154 </span>            :         //   present in outputCoverVariables.  (closer can be roughly estimated
<span class="lineNum">     155 </span>            :         //   as smaller difference between the variable numbers.)
<span class="lineNum">     156 </span><span class="lineCov">          4 :     }</span>
<span class="lineNum">     157 </span>            :     
<span class="lineNum">     158 </span>            : } // end namespace
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
